package com.zhijian.warehouse.manage.entity.vo.response;

import com.zhijian.util.BeanUtil;
import com.zhijian.warehouse.manage.enums.ProductEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 库存管理 回显vo
 *
 * @author auto
 * @version 1.0
 * @date 2024-10-27 13:42:54
 */
@Data
@Api(tags = "库存管理回显vo")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class StoreVo implements Serializable {

    private static final long serialVersionUID = -1;

    /**
     * 主键自增id
     */
    @ApiModelProperty("主键自增id")
    private Long id;

    /**
     * 商品id
     */
    @ApiModelProperty("商品id")
    private Long productId;

    /**
     * 仓库id
     */
    @ApiModelProperty("仓库id")
    private Long warehouseId;

    /**
     * 库位id
     */
    @ApiModelProperty("库位id")
    @NotNull(message = "库位id不能为空")
    private Long warehouseLocationId;

    /**
     * 商品库存
     */
    private BigDecimal productCount;
    /**
     * 商品库存
     */
    @ApiModelProperty("商品库存")
    private String productCountInit;

    /**
     * 期初库存
     */
    private BigDecimal earlyCount;
    @ApiModelProperty("期初库存")
    private String earlyCountInit;

    /**
     * 期末库存
     */
    @ApiModelProperty("期末库存")
    private String endCountInit;
    private BigDecimal endCount;

    /**
     * 期初时间 yyyy-MM-dd
     */
    @ApiModelProperty("期初时间 yyyy-MM-dd")
    private String earlyTime;

    /**
     * 期末时间 yyyy-MM-dd
     */
    @ApiModelProperty("期末时间 yyyy-MM-dd")
    private String endTime;

    /**
     * 创建时间
     */
    @ApiModelProperty("创建时间")
    private String createTime;

    /**
     * 创建人ID(当前登陆人id)
     */
    @ApiModelProperty("创建人ID(当前登陆人id)")
    private Long createUserId;

    /**
     * 创建人姓名创建人姓名(当前登陆人姓名)
     */
    @ApiModelProperty("创建人姓名创建人姓名(当前登陆人姓名)")
    private String createUserName;

    /**
     * 修改时间
     */
    @ApiModelProperty("修改时间")
    private String updateTime;

    /**
     * 修改人ID(当前登陆人id)
     */
    @ApiModelProperty("修改人ID(当前登陆人id)")
    private Long updateUserId;

    /**
     * 修改人姓名(当前登陆人姓名)
     */
    @ApiModelProperty("修改人姓名(当前登陆人姓名)")
    private String updateUserName;

    @ApiModelProperty("商品条码")
    private String barCode;


    /**
     * 商品名称
     */
    @ApiModelProperty("商品名称")
    private String productName;
    /**
     * 商品编号
     */
    @ApiModelProperty("商品编号")
    private String productNumber;
    @ApiModelProperty("品类")
    private String categoryName;
    @ApiModelProperty("库位")
    private String warehouseLocationName;
    @ApiModelProperty("单位")
    private String unitName;
    @ApiModelProperty("产品状态")
    private String productStatusStr;
    private Integer productStatus;

    @ApiModelProperty("商品规格")
    private String productModel;

    @ApiModelProperty("商品RFID")
    private String productRfId;

    @ApiModelProperty("仓库")
    private String warehouseName;

    private BigDecimal waitStoreInCount;
    @ApiModelProperty("待入库数量")
    private String waitStoreInCountInit;
    @ApiModelProperty("待出库数量")
    private String waitStoreOutCountInit;
    private BigDecimal waitStoreOutCount;
    @ApiModelProperty("库存可用数量")
    private String storeUsableCountInit;
    private BigDecimal storeUsableCount;
    private Integer unitFraction;

    public String getProductStatusStr() {
        if (this.productStatus != null && ProductEnum.StatusEnum.getByCode(this.productStatus) != null) {
            return ProductEnum.StatusEnum.getByCode(this.productStatus).getDesc();
        }
        return null;
    }

    public String getStoreUsableCountInit() {
        return initData(this.storeUsableCount);
    }

    public String getWaitStoreOutCountInit() {
        return initData(this.waitStoreOutCount);
    }

    public String getWaitStoreInCountInit() {
        return initData(this.waitStoreInCount);
    }

    public String getEndCountInit() {
        return initData(this.endCount);
    }

    public String getEarlyCountInit() {
        return initData(this.earlyCount);
    }

    public String getProductCountInit() {
        return initData(this.productCount);
    }
    //初始化 数据 如果不是空的则补全小数位
    public String initData(BigDecimal data) {
        if (data == null) {
            return BigDecimal.ZERO.toString();
        }
        if (BeanUtil.isEmpty(this.unitFraction))
            return data.toString();
        return data.setScale(this.unitFraction, RoundingMode.HALF_UP).toString();
    }
}
